
// INCLUDES ********************************************************************

#include "ToggleButton.h"


// NAMESPACES ******************************************************************

using namespace Meteor;


#pragma mark -
#pragma mark Constructors/Destructor
// -----------------------------------------------------------------------------

ToggleButton::ToggleButton( const std::string& normalImage, 
                            const std::string& altImage)

: Button( normalImage, altImage, 0)
{

}

// -----------------------------------------------------------------------------

ToggleButton::ToggleButton( const std::string& normalImage, 
                            const std::string& altImage,
                            const uint32_t zIndex)

: Button( normalImage, altImage, 0), mActive( false)
{    

}

// -----------------------------------------------------------------------------

ToggleButton::~ToggleButton()
{

}


#pragma mark -
#pragma mark Touch handling
// -----------------------------------------------------------------------------

void ToggleButton::TouchEnded( const Vector2D& position, double duration)
{
    Rectangle imageRect( mPosition.X() - ( mSize.X() * mAnchorPoint.X()), 
                         mPosition.Y() - ( mSize.Y() * mAnchorPoint.Y()), 
                         mSize.X(), 
                         mSize.Y());
                
    if ( imageRect.Contains( position))
    {
        if ( mTextureOrignal && mActive)
        {
            mTexture = mTextureOrignal;
            
            mActive = false;
        }
    
        else if ( mActive == false)
        {
            mActive = true;
        }
    
        mDidSwallowTouch = true;
        
        if ( mCallback != 0)
        {
            ( *mCallback)();
        }
    }
    else
    {
        mDidSwallowTouch = false;
    }
}
